﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Web.UI.WebControls;
using OrganizedIN.BussinessServices;
using OrganizedIN.BAL;
using Microsoft.ApplicationBlocks.Data;

namespace OrganizedIN.UI.ToDo
{
    public partial class add_new_todos : System.Web.UI.Page
    {
        public string dtdate;
        private DateTime _dttime;
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSave.Attributes.Add("onClick", "return CheckValidation()");
            dtdate = DateTime.Now.ToLongDateString();
            _dttime = Convert.ToDateTime(dtdate);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                //check to make sure a file is selected
                if (FileUpload1.HasFile)
                {
                    //create the path to save the file to
                    string fileName = Path.Combine(Server.MapPath("~/UploadDocument"), FileUpload1.FileName);
                    //save the file to our local path
                    FileUpload1.SaveAs(fileName);
                }
                Add_New_Todo(Convert.ToString(Session["UserID"]), _dttime.ToShortDateString(), Convert.ToString(txtSummary.Text), Convert.ToString(txtDescription.Text), Convert.ToString(FileUpload1.FileName));
                Clear();
                lblErrMsg.Text = "Record saved successfully.";
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = ex.ToString();
            }
           
        }
        public static void Add_New_Todo(string UserName, string Todo_date, string Todo_Summary, string Todo_Desc, string Todo_Attachment)
        {
            SqlService objservices = new SqlService();
            SqlParameter[] param = new SqlParameter[5];

            param[0] = new SqlParameter("@vcrUserName", SqlDbType.VarChar, 100);
            param[0].Value = UserName;

            param[1] = new SqlParameter("@dtmTodoDate", SqlDbType.VarChar, 100);
            param[1].Value = Todo_date;

            param[2] = new SqlParameter("@vcrTodoSummary", SqlDbType.VarChar, 100);
            param[2].Value = Todo_Summary;

            param[3] = new SqlParameter("@vcrTodoDesc", SqlDbType.VarChar, 100);
            param[3].Value = Todo_Desc;

            param[4] = new SqlParameter("@vcrTodoAttachment", SqlDbType.VarChar, 100);
            param[4].Value = Todo_Attachment;


            SqlHelper.ExecuteNonQuery(objservices.ConnectionString, CommandType.StoredProcedure, "usp_ToDos_AddNewTodos", param);


        }
        protected void Clear()
        {
            txtSummary.Text = string.Empty;
            txtDescription.Text = string.Empty;
           
        }

        protected void idorg_Click(object sender, EventArgs e)
        {
            
        }
    }
}